<?php

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

use PhpAmqpLib\Connection\AMQPStreamConnection;

class Xiaofeizhe extends Command
{
    protected function configure()
    {
        $this->setName('xiaofei')->setDescription('rabbitmq消费者');
    }

    protected function execute(Input $input, Output $output)
    {
        $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
        $channel = $connection->channel();
        $channel->queue_declare('hello', false, false, false, false);
        $callback = function ($msg) {

            //逻辑部分
            $req_data = $msg->getBody();
            
            echo $req_data;


            //回复
            $msg->ack();
        };
        $channel->basic_qos(null, 1, false);
        $channel->basic_consume('hello', '', false, false, false, false, $callback);

        while (count($channel->callbacks)) {
            $channel->wait();
        }


        $channel->close();
        $connection->close();


    }
}